home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Problem with Watcom C++ 10.5
- Date: Sun, 10 Mar 96 14:20:06 GMT
- Organization: none
- Message-ID: <826467606snz@genesis.demon.co.uk>
- References: <31426ACB.6AA1@scsn.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <31426ACB.6AA1@scsn.net> mdorsey@scsn.net "Michael" writes:
-
- >I'm having a rather strange problem with Watcom C. When using functions
- >that output to stdout (ie printf()), it is not flushing to the screen
- >until a newline is sent. For example:
- >
- >void main(void)
-
- If you want your program to mean anything write that as int main(void)
- void main(void) simply means that the whole program has no defined behaviour.
-
- >{
- > printf("Hit Y for yes, N for no: ");
- > yn();
-
- And put here:
-
- return 0;
- >}
- >
- >
- >yn() gets the key stroke and prints yes or no. The problem is that the
- >statement will not be printed until the newline from the answer is sent.
-
- This is quite normal and indicates that Watcom defaults to line buffering
- on stdout when it is connected to the terminal. A correct program can't
- assume that output buffers will be flushed when you read input. You can
- usually assume that output to an 'interactive device' such as your terminal
- will be flushed when a newline is written, however a C implementation isn't
- even required to do this if it provides suitable documentation.
-
- >Kind of hard to answer a question if you can't see it. I can get around
- >it by flushing stdout after printf(), but I was kind of hoping there was
- >some type of variable I could set to turn off buffering of stdout.
-
- In your code above you must either ensure that stdout is not buffered by
- calling setbuf() or setvbuf() at the start of the program. However
- fflush(stdout) is probably a better solution since you don't lose buffering.
- It isn't likely to be a significant code overhead in your program. As well
- as putting it after printf() you might also be able to put it into your
- input functions such as yn().
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-